/*  File Name	: Daemon.h
 *  Author		: Pang Jiacai
 *	 E-mail		: 823960168@qq.com
 *  Created on	: 2012-6-29
 *  Description:
 */

#ifndef DAEMON_H_
#define DAEMON_H_

#include "Reactor.h"
#include "EventHandler.h"
#include "ProcessManager.h"

const std::string CHAT_SERVICE="chat";
const std::string ENGINE_SERVICE="engine";
const std::string GATE_SERVICE="gate";
const std::string AUTH_SERVICE="auth";
const std::string SANDBOX="sandbox";
const std::string DBSERVER="dbserver";
const std::string DIRCSERVER="dircserver";

class Daemon:virtual public EventHandler
{
public:
	virtual ~Daemon();

	static Daemon *instance(void);

	virtual int handle_signal(int signum);

	virtual int handle_exit(int pid);

	int start_game(int argc,char *argv[]);

	int stop_game(void);

private:
	Daemon();

	int start_debug_version(int argc,char *argv[]);

	int start_online_version(int argc,char *argv[]);

	void register_signal(void);

private:

	int start_daemon(int argc,char *argv[]);

	int start_service(int argc,char *argv[]);

	int spawn_child(std::string type,int index);

	static Daemon *instance_;

	ProcessManager *process_manager_;

	bool is_shutdown_;
};

#endif /* DAEMON_H_ */
